package com.cust.cow.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cust.cow.common.Result;
import com.cust.cow.mapper.CollectSemenLogMapper;
import com.cust.cow.pojo.cattleAddressBase;
import com.cust.cow.pojo.collectSemenLog;
import com.cust.cow.service.CollectSemenLog;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CollectSemenLogImpl implements CollectSemenLog {
    @Autowired
    public CollectSemenLogMapper collectSemenLogMapper;
    @Override
    public List<collectSemenLog> findCollectSemenLogAll() {
        return collectSemenLogMapper.findCollectSemenLogAll();
    }

    @Override
    public Result insertCollectSemenLog(collectSemenLog collectSemenLog) {
        collectSemenLogMapper.insertCollectSemenLog(collectSemenLog);
        return new Result(200, "插入成功");
    }

    @Override
    public Result deleteCollectSemenLog(Integer cattleId) {
        collectSemenLogMapper.deleteCollectSemenLog(cattleId);
        return new Result(200, "删除成功");
    }

    @Override
    public Result updateCollectSemenLog(collectSemenLog collectSemenLog) {
        UpdateWrapper<collectSemenLog> wrapper = new UpdateWrapper<>();
        wrapper.eq("cattle_id",collectSemenLog.getCattleId())
                .set("collect_semen_date", collectSemenLog.getCollectSemenDate())
                .set("state",collectSemenLog.getState());
        int result =  collectSemenLogMapper.update(collectSemenLog,wrapper);
        if (result <= 0) {
            return new Result(100, "更新失败");
        }
        return new Result(200, "更新成功");
    }
}
